<template>
    <div>
      <div class="main">
       <!-- <div v-if="isRadio" class="modal modal-record" bindtap="toggleRecordModal">
          <div class="modal-body" catchtap="toggleWithoutAction">
            <span class="desc">{{RecordDesc[recordStatus]}}</span>
            <div class="dot" catchtouchstart="handleRecording" catchtouchmove="handleRecordingMove"
                  catchtouchend="handleRecordingCancel" catchtouchcancel="handleRecordingCancel">
              <img class="icon-mic" src="../../webim/images/mic@2x.png"/>
            </div>
          </div>
        </div>-->
        <div  class="scroll_view" >
          <div class="message" >
            <div class="time">
              <span>2018-12-12</span>
            </div>
            <div class="main">
              <div class="user">
                <span>son</span>
              </div>
              <img class="avatar" src="../../webim/images/number.png"/>
              <div class="msg">
                <div>
                  <span style="float: left;margin-top: 2px;">12334234</span>
                </div>
                <!--<div wx:if="{{ item.msg.type == 'img' || item.msg.type == 'audio' || item.msg.type == 'video' || item.msg.type == 'audio'}}">
                  <template is="{{ item.msg.type }}" data="{{ item, msgView }}"/>
                </div>-->
                <!--<div wx:elif="{{ item.msg.type == 'txt' || item.msg.type == 'emoji' }}">
                  <div class="template" wx:for="{{ item.msg.data }}" wx:key="">
                    <template is="{{ item.type }}" data="{{ item }}"/>
                  </div>
                </div>-->
              </div>
            </div>
          </div>
        </div>
<!--

        <template name="txt">
          <text style="float: left;margin-top: 2px;">{{ item.data }}</text>
        </template>

        <template name="emoji">
          <image class="avatar" src="{{'../../images/faces/' + item.data }}"
                 style="width: 25px;height: 25px;margin: 0 0 2px 0;float: left;"/>
        </template>
        <template name="img">
          <image class="avatar" src="{{ item.msg.data }}" style="width:90px;height: 120px;margin: 2px auto;"
                 mode="aspectFit" bindtap="previewImage" data-url="{{ item.msg.data }}"/>
        </template>
        <template name="video">
          <video src="{{ item.msg.data }}" controls autoplay/>
        </template>

        <template name="audio">
          <audio src="{{ item.msg.url }}" controls autoplay/>
        </template>
-->


        <div class="room_bar">
          <div>
            <div class="f-row">
              <input class="f news" type="text" v-model="chattext"
                     placeholder="输入新消息" placeholder-style="color:#CFCFCF;padding-left:5px;" />
              <!--<button wx:else class="f btn-recording" catchtouchstart="handleRecording"
                      catchtouchend="handleRecordingCancel" catchtouchcancel="handleRecordingCancel">按住 说话
              </button>-->
              <button class="send_btn" @click="sendMsg">发送</button>
            </div>
          </div>
          <div class="other_func">
            <div class="open_emoji" >
              <img src="../../webim/images/Emoji.png"/>
            </div>
            <div class="send_image">
              <img src="../../webim/images/iconImage@2x.png" style="height: 18px;"/>
            </div>
            <div class="open_camera">
              <img src="../../webim/images/iconCamera@2x.png" style="width: 26px;"/>
            </div>
            <div class="v-record">
              <!--<img class="icon-record"
                     src="{{recordStatus != RecordStatus.HIDE ? '../../images/iconAudioActive@2x.png' : '../../images/iconAudio@2x.png'}}"/>-->
            </div>
            <div class="send_image">
              <img src="../../webim/images/iconLocation@2x.png" style="height: 18px;"/>
            </div>
          </div>
          <!--<div class="emoji_list" class="{{ show }}" indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}"
                  interval="{{interval}}" duration="{{duration}}">
            <div>
              <div>
                <div class="emoji_item">
                  <img wx:for="{{ emojiObj.map1 }}" src="{{ emojiObj.path + item }}" wx:key=""
                         bindtap="sendEmoji" data-emoji="{{ index }}"/>
                </div>
                <div class="emoji_item">
                  <img wx:for="{{ emojiObj.map2 }}" src="{{ emojiObj.path + item }}" wx:key=""
                         bindtap="sendEmoji" data-emoji="{{ index }}"/>
                </div>
                <div class="emoji_item">
                  <img wx:for="{{ emojiObj.map3 }}" src="{{ emojiObj.path + item }}" wx:key=""
                         bindtap="sendEmoji" data-emoji="{{ index }}"/>
                </div>
              </div>
            </div>
            <div class="second">
              <div>
                <div class="emoji_item">
                  <img wx:for="{{ emojiObj.map4 }}" src="{{ emojiObj.path + item }}" wx:key=""
                         bindtap="sendEmoji" data-emoji="{{ index }}"/>
                </div>
                <div class="emoji_item">
                  <img wx:for="{{ emojiObj.map5 }}" src="{{ emojiObj.path + item }}" wx:key=""
                         bindtap="sendEmoji" data-emoji="{{ index }}"/>
                </div>
                <div class="emoji_item">
                  <img wx:for="{{ emojiObj.map6 }}" src="{{ emojiObj.path + item }}" wx:key=""
                         bindtap="sendEmoji" data-emoji="{{ index }}"/>
                </div>
              </div>
            </div>
          </div>-->
        </div>
      </div>
    </div>
</template>

<script>
  import WebIM from '../../webimjs/Lib/WebIM'
  import {mapGetters} from 'vuex'
  export default {
    name: '',
    props: {},
    data() {
      return {
        chattext: '发送的信息'
      }
    },
    computed: {
      ...mapGetters({getTextMessage: 'getTextMessage'})
    },
    methods: {
      sendMsg () {
        let _this = this
        console.log('send')
      // 单聊发送文本消息
        var id = WebIM.conn.getUniqueId();                 // 生成本地消息id
        var msg = new WebIM.message('txt', id);      // 创建文本消息
        msg.set({
          msg: _this.chattext,                  // 消息内容
          to: 'son',                          // 接收消息对象（用户id）
          roomType: false,
          success: function (id, serverMsgId) {

            _this.$store.dispatch('fetchTextMessage', msg)
            console.log('send private text Success!');
          },
          fail: function(e){
            console.log("Send private text error");
          }
        });
        msg.body.chatType = 'singleChat';
        WebIM.conn.send(msg.body);

        console.log(msg)
      }
    },
    mounted() {
    },
    components: {}


  }
</script>
<style>
  .main {
    width: 100%;
    height: 50%;
  }

  .scroll_view, .scroll_view_change {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 75px;
  }

  .scroll_view_change {
    bottom: 220px;
  }

  .message {
    width: 92%;
    height: auto;
    padding: 10px 15px;
  }

  .time {
    margin: 7px 0;
    text-align: center;
  }

  .time text {
    display: inline-block;
    padding: 3px 10px 0 10px;
    font-size: 12px;
    color: #fff;
    line-height: 14px;
    border-radius: 2px;
    background-color: #dcdcdc;
  }

  .user text {
    margin: auto auto 4px 0;
    font-size: 12px;
    color: #dcdcdc;
    display: block;
  }

  .avatar {
    width: 32px;
    height: 30px;
    margin: 0 10px 0 0;
    padding-top: 3px;
    border-radius: 3px;
    float: left;
  }

  .msg {
  //display: flex;
  //justify-content: center;
    display: inline-block;
    position: relative;
    padding: 5px 10px;
    max-width: calc(85% - 40px);
  /// min-height:(12 + 5 * 2) px;
    font-size: 12px;
    overflow: hidden;
    text-align: left;
    word-break: break-all;
    background-color: #EDEDED;
    border-radius: 4px;
  }

  .msg text {
    line-height: 1.5;
  }

  .msg :before {
    content: " ";
    position: absolute;
    top: 9px;
    right: 100%;
    border: 6px solid transparent;
    border-right-color: #EDEDED;
  }

  .self {
    text-align: right;
  }

  .self .avatar {
    float: right;
    margin: 0 0 0 10px;
  }

  .self .user {
    margin: auto 2px 4px auto;
    font-size: 12px;
    color: #dcdcdc;
  }

  .self .msg {
    background-color: #b2e281;
  }

  .self .msg :before {
    right: inherit;
    left: 100%;
    border-right-color: transparent;
    border-left-color: #b2e281;
  }

  .room_bar {
    width: 100%;
    height: auto;
    border-top: 1px solid #CFCFCF;
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 1;
    background-color: #FFFFFF;
  }

  .send_btn {
    width: 40px;
    height: 30px;
    line-height: 30px;
    font-size: 14px;
    color: #000;
    padding: 0;
    /*display: inline-block;*/
    /*float: right;*/
    margin: 4px 8px auto auto;
    background-color: #fff;
  }

  .audio {
    width: 4.5%;
    height: 40%;
    border: 1px solid rgb(135, 152, 164);
    border-radius: 50px;
    padding: 3px 4px;
    margin-left: 10px;
  }

  .room_bar form {
    width: 100%;
    height: 40px;
    padding: 0;
    display: block;
  }

  .news {
    width: 79%;
    height: 30px;
    border: 1px solid #CFCFCF;
    border-radius: 5px;
    font-size: 14px;
    padding-left: 4px;
    /*display: inline-block;*/
    /*float: left;*/
    margin: 4px 2px 4px 6px;
  }

  .emoj {
    width: 6.8%;
    height: 60%;
    margin-right: 10px;
  }

  .other_func {
    width: 100%;
    height: 30px;
    float: left;
    display: flex;
    align-items: center;
    justify-content: space-between;

  }

  .other_func image {
    width: 21px;
    height: 20px;
  }

  .emoji_list {
    margin-top: 30px;
    width: 100%;
    height: 145px;
    background-color: #dddddd;
    padding-top: 10px;
    padding-left: 3%;
    display: none;
  }

  .showEmoji {
    margin-top: 30px;
    width: 100%;
    height: 145px;
    background-color: #dddddd;
    padding-top: 10px;
    padding-left: 3%;
    display: block;
  }

  .emoji_list image, .showEmoji image {
    width: 26px;
    height: 26px;
    margin: 5px 2%;
  }

  .emoji {
    width: 26px;
    height: 26px;
    margin: 0 0;
  }

  .emoji_item {
    display: flex;
    justify-content: space-around;
    margin-right: 20px;
  }

  .template {
    display: inline;
  }

  .open_emoji, .send_image, .open_camera, .v-record {
    width: 40px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .v-record {
    margin-right: 15px;
  }

  .v-record .icon-record {
    width: 9px;
    height: 20px;
  }

  .icon-play {
    width: 25px;
    height: 25px;
    margin: 0 10px;
  }

  .icon-mic {
    width: 13px;
    height: 25px;
  }

  .modal {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .modal-record .modal-body {
    width: 164px;
    height: 164px;
    background-color: rgba(135, 152, 164, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 3px;
  }

  .modal-record .desc {
    color: rgb(112, 126, 137);
    font-size: 13px;
    margin-bottom: 20px;
  }

  .modal-record .dot {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
  }

</style>
